  var req = false;
  var res = undefined;
  var url = "commentthread.php";
  var pid = "";
  var param;
  var categories = [];
  var category_vaue = "";
  var url1 = "categorybrands.php";
  var mygrppress = false;

  $(document).ready(function() {
  
  jQuery.ajaxSetup({async:false});
  $("#hidden").hide();
  $("#prodpic").hide();

  //tab thing
  $("#addtowishlist").live('click',function() {

    var ppid = Number($(this).attr('alt'));

    
    $.post('productview.php',{ld:'addtowishlist',pid:ppid},function(res){
      
    alert('added '+ppid+' to ur wish list'+res);  
      
    });
   
    e.stopPropagation();

    });


    $("#wishlist").click(function() {   

    $.post('productview.php',{ld:'loadwishlist'},function(res){
      
      $('#fullcontainer').html(res);

      e.stopPropagation();

    },'html');
   

  });

      $('.namedisplay').live('click',function(e){ 

        //var fname = $(this).text();

        var wpid = $(this).attr('id');
                
        var wppid = Number(wpid.substring('u'.length,wpid.length)); 

        //alert(wppid);

        $.post('friends.php',{ld:'viewprofile',vf:wppid},function(res){
          
          $('#fullcontainer').html(res);

        },'html');


      e.stopPropagation();  } );

  
  $('#list3').change( function(){
    
   var e1 = $("#list3 option:selected").text(); 
   //$('#bottomcontainer').text('selected'+e1);

    getproduct(e1);

    e.stopPropagation();

  });


  $.post(url1,{ld:'allcategories'},function(responsedata){ 
  
  categories["startList"] = responsedata.split("#");
  
  //$('#bottomcontainer').append("append test");

  fillSelect('startList',document.forms['tripleplay']['List1']);

  },"text"); 
  
  //$(foo).dialog({ autoOpen: false }); 
  
  $('#viewmyprofile').click( function(e) {


  $.post('friends.php',{ld:'loadmyprofile'},function(res){
    

  //alert(res);
  $("#fullcontainer").html(res).hide().slideDown();


  },'html');


  e.stopPropagation();
  
  }); 

  $('.addbuddy').live('click',function(){  
  
  var frid = $(this).attr('alt');


  $.post('friends.php',{ld:'addthisfriend',fr:frid},function(res){
    
      alert('Added this'+frid+'buddy to ur freinds list'+res);
      $('.addbuddy').remove();

  },'text');
  
  

  });

  $('#grpmemberslistform .rowleft').live('click',function(){  
  
  

  //$.post('creategroups.php',{ld:'removefromgroup',})
  
  
  });

  $('#creategroup').click( function(e) {
  
  $('input[name=newgroupname]').clearField('Enter Group Name');
  $('textarea[id=groupproducts]').clearField('Enter prducts to be associated with');
  $('textarea[id=newgroupdesc]').clearField('Enter brief group discussion to be display in group directory');
  
  
  $("#creategroupform").dialog({ minHeight: 300,minWidth: 600,closeOnEscape:true});

  e.stopPropagation();
  
    });
  
  $('#mygroups').click(function(e) {
      
      
     var count = $('#buttonlist li').children().length;
     
     if(count > 5 )
     {
         mygrppress == true;
     }
    
    
    $.post('creategroups.php',{ld:'listallhisgroups'},function(response){
      
    $('#newbuttonlist').html(response).hide().slideDown('slow');
    

    },'html');

            
    e.stopPropagation();

    });

   //$('.postbox').live('click',function(e){ alert('test'); e.stopPropagation(); });
   

   $('#grpmembers.stdlink').live('click',function(){
     
    
    $.post('creategroups.php',{ld:'editgrpmemebers'},function(res){
     
      //alert(res);

      $('#fullcontainer').html(res);

      //$('#hidden').append(res);

      //$('#groupmemberlist').dialog({ minHeight: 300,minWidth: 600,closeOnEscape:true});

    },'html');
    
    });


    $('.commentproduct :[id^=goto]').live('click',function(){
      
      var t = $(this).text();

      getproduct(t);

    });



  
});//end of document ready function           
  
  function editwishlist(wpid)
  {
    
    
    var wppid = Number(wpid.substring('wp'.length,wpid.length)); 

    $.post('productview.php',{ld:'editwishlist',wp:wppid},function(res){
      
    alert('deleted the product');  
    $("#l"+wppid).remove();

    });
    return false;
  }


  function creategroup()
  {
    var newgrpname = $('#newgroupname').attr('value');
    var grproducts = $('#groupproducts').attr('value');
    var newgrpdesc = $('#newgroupdesc').attr('value');
    //$('#hidden').html('<img id="loader" src="loader.gif">').dialog();
    //$('#bottomcontainer').text('calling before <br>');
    var url3 = 'creategroups.php';
    $("#creategroupform").dialog('destroy');

    $.post(url3,{ld:'creategroup',newgroupname:newgrpname,groupproducts:grproducts,newgroupdesc:newgrpdesc},function(resdata){
    
    $("#fullcontainer").html(resdata);
    
    addgrpfriends();

    

    },"html");

  }

  function editgrpmembers(id)
  {
    
      var fid = Number(id.substring('wp'.length,id.length));

      $.post('creatgroups.php',{ld:'removefromgroup',fd:fid});


  }

  function addgrpfriends()
  {
      

      $.post('friends.php',{ld:'freindstoadd'},function(response){
      
      

      $("#addgrpfriend").html(response);

      
      $("#addgrpfriend").dialog({ minHeight: 300,minWidth: 600});

      },'html');

     e.stopPropagation();  

  }


  function checkgrpfriend(fid)
  {
    
    var ffid = Number(fid.substring('grpfriendtick'.length,fid.length));

    
    $.post('creategroups.php',{ld:'addthisgrpfriend',nwfid:ffid},function(resch){});

    
    e.stopPropagation();

  }


  function newgrouppost()
  {
    var nwpost = $('#newpostgrp').val();

    $.post('creategroups.php',{ld:'nwgrppost',nwp:nwpost},function(res){
      
    $("#grppostlist").append(res).hide().slideDown('slow');
    //$('#oldpost :contains('+nwpost+')').hide().slideDown('slow');


    },'html');

    e.stopPropagation();

  }

  function viewgroup(gvid)
  {
    
    var gid = Number(gvid.substring('grp'.length,gvid.length)); 
    $.post('creategroups.php',{ld:'viewagroup',grpid:gid},function(response){
      
      $('#fullcontainer').html(response);
   
    
    },'html');

    e.stopPropagation();
  }

  function viewprofile(fpid)
  {
    
    var ffpid = Number(fpid.substring('friendname'.length,fpid.length));

    $.post('friends.php',{ld:'viewprofile',fid:ffpid},function(res){
      
    $('#fullcontainer').html(res);
    //alert(res);

    },'html');

    e.stopPropagation();

  }


var nLists = 3; //number of select lists in the set

function fillSelect (currCat,currList)
{
          //$('#bottomcontainer').append(currCat);
          category_value = currCat;
          var step = Number(currList.name.replace(/\D/g,""));
          var ajaxwait = false;
          
          if(step == 2)
          {
                $.post('commentthread.php',{ld:'listproducts',cat:currCat}, function(response){ 
                $('#bottomcontainer').html(response);
                },"html");
                
                jQuery.ajaxSetup({async:false});
                $.get('categorybrands.php',{ld:'listbrands',cat:currCat},function(responsedata){ 
                            
                categories[currCat] = responsedata.split("#");
                
                },"text");

          }

          if(step == '3')
          {
             
            
                  $.get('categorybrands.php',{ld:'listproducts',selbrand:currCat},function(res){
                    
                  categories[currCat] = res.split("#");      

                  },'text');


          }


          for (i=step; i<nLists+1; i++) 
          {
              document.forms['tripleplay']['List'+i].length = 1;
              document.forms['tripleplay']['List'+i].selectedIndex = 0;
            
          }
          
          var nCat = categories[currCat];

          for (var each in nCat) 
          {
              //$('#bottomcontainer').append('//'+nCat[each]+'//');
              var nOption = document.createElement('option'); 
              var nData = document.createTextNode(nCat[each]); 
              nOption.setAttribute('value',nCat[each]);
              
               nOption.appendChild(nData); 
              currList.appendChild(nOption); 
          } 
}

  
  function getproduct(pname) 
  {

      //$('#bottomcontainer').text('selected'+pname);
      $("#prodpic").show();

      $.post('productview.php',{ld:'viewaproduct',prod:pname}, function(res){ 
    
      var parr = res.split('#');

      var tabthing = $('#productspec').html();
      $('#bottomcontainer').html(tabthing);
      $('#prodpic #addtowishlist').attr({
      'alt': parr[4]
       });
     
      $("ul.tabs li:first").addClass("active").show(); //Activate first tab
      $("#tab1.tab_content h2").append(parr[0]);
      $("#tab2.tab_content h2").append(parr[1]+'$ available at '+parr[2]);
            
      $(".tab_content:first").show(); //Show first tab content

      //On Click Event
      $("ul.tabs li").click(function(e) {

      $.post('productview.php',{ld:'loadcomments',pid:parr[4]},function(res){
       
      
      $("#tab3.tab_content").html('<h2>User Reviews</h2><br>'+res);    



      },'html');   
    
    $("ul.tabs li").removeClass("active"); //Remove any "active" class
    $(this).addClass("active"); //Add "active" class to selected tab
    $(".tab_content").hide(); //Hide all tab content

    var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
    $(activeTab).fadeIn(); //Fade in the active ID content
    
    e.stopPropagation();
    return false;

     });

        
    });

    return false;

   } 


function viewallcomments(curr_pid)
{ 
  var s,s1; 
  s1 = curr_pid.substring(7,curr_pid.length);
  var w_pid = Number(s1);
  //$('#bottomcontainer').text(w_pid);
  //$('#bottomcontainer').append('#'+curr_pid.length);
  //var w_pid = curr_pid[curr_pid.length-1];
  $.post(url,{ld:'viewallcomments',vpid:w_pid},function(responsedata1){ 
  s = 'commentbox' + w_pid;
  $('#'+s ).html(responsedata1).hide().slideDown();
  },"html");
}



function commenton()
{
    alert('commenton');  
    var ele1 = document.createElement("input");
    var att1 = document.createAttribute("type");
    att1.nodeValue = "text";
    ele1.setAttributeNode(att1);
    var att1 = document.createAttribute("size");
    att1.nodeValue = "90";
    ele1.setAttributeNode(att1);
    var att1 = document.createAttribute("onkeypress");
    att1.nodeValue = "return confirmcomment(event,this.id)";
    ele1.setAttributeNode(att1);
    var att1 = document.createAttribute("id");
    att1.nodeValue = "commenttext" + pid;
    ele1.setAttributeNode(att1);
    document.getElementById(pid).insertAdjacentElement("beforeEnd",ele1);
    var pid1= "spancomment" + pid;
    document.getElementById(pid1).removeAttribute("onclick");
    //document.getElementById(pid).style.height = ((document.getElementById(pid).offsetHeight) + 15) + "px";

}
function copythat(nw)
{
    pid = nw;

}

function confirmcomment(e,cpid)
{
  if(e.keyCode==13)
  {
    var cmtext = document.getElementById("commenttext"+pid).value;
    document.getElementById("commenttext"+pid).value = " ";
    var ccpid = Number(cpid.substring('commenttextp'.length,cpid.length));
    $.post(url,{ld:'commentin',cm:cmtext,cid:ccpid});
  }
  return;
  
}

function commentout()
{
  document.getElementById(pid).removeChild(document.getElementById(pid).lastChild);
}

function viewfriends()
{
  var url2 = "friends.php";
  $.post(url2,{ld:'listallfriends'}, function(responsedata) {
  
  $('#fullcontainer').html(responsedata); 

  },"html");

}

	